-- add_counterattack
-- created by wangy
-- 概率增加反击伤害（怪物）

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 对敌伤害触发
    trigger = function(who, prop, arg)
        if DungeonM.getRandSeed("add_counterattack") % 1000 >= prop[3] then
            return 0;
        end

        local extraDamage = 0;
        if tonumber(prop[2]) > 0 then
            extraDamage = math.modf(prop[2] * arg / 1000);
        end

        -- 降低重击效果
        local propId = prop[1];
        local p = PropM.combine(ME.user, "reduce_negative", propId);
        extraDamage = PropM.apply(p, extraDamage);

        -- 触发吸血标记
        PropM.trigger(who, "add_counterattack_absorb", 1);

        return math.max(0, extraDamage);
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;
        local ron = tonumber(prop[3]) / 10;
        local add = 100 + tonumber(prop[2]) / 10;

        desc = string.gsub(desc, "{0}", add);
        desc = string.gsub(desc, "{1}", ron);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
